import base from './base';
import vm from '@/main';

export default class login extends base {
    /**
* [login 后台登录]
*
* @return  {[type]}  [return description]
*/
    static login (params) {
        let url = 'Login/index';
        return this.post(url, params, true).then(data => {
            vm.$store.commit('login', data.data);
            vm.$Message.success(data.msg);
            vm.$router.push({
                name: 'home_index'
            });
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
        });
    }

    /**
* [logout 后台登出]
*
* @return  {[type]}  [return description]
*/
    static logout () {
        let url = 'Login/logout';
        return this.get(url).then(() => {
            vm.$store.commit('logout', vm);
            vm.$store.commit('clearOpenedSubmenu');
            vm.$router.push({
                name: 'login'
            });
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
        });
    }
}
